Java Dwarf Manager

C# .NET Dwarf Manager is here re-implemented using Java, the Apache Jakarta Struts MVC framework, the Apache Jakarta Tomcat JSP Web Server, and the Postgresql SQL database. Except for Java, all elements of this system are Open Source.

Model-View-Controller

Struts provides a framework whereby Servlet/JSP applications can be implemented using the Model-View-Controller (MVC) design pattern. In this pattern the look-and-feel of a web page is separated from the underlying data model, so each can be implemented and modified independently. The flow between pages is also configured and controlled outside the individual page definitions.

The View is implemented using Java Server Pages (JSP). Java Server Pages are normally filled with embedded Java code, but the Struts framework provides extension tags for numerous functions including generating and populating html controls (<html:text>), managing errors (<html:errors>), and iterating over data lists (<logic:iterate>). The following JSP files are used in Dwarf Manager:

Note the following are static screen shots. This site is not dynamically hosted.

Generated HTMLJSP Source (View->Source)
Main Main.jsp
AddDwarf AddDwarf.jsp
AddMountain AddMountain.jsp
UpdateDwarf UpdateDwarf.jsp
UpdateMountain UpdateMountain.jsp

The Model is implemented as Java Beans subclassed from ActionForm. Three Form beans were defined:

Form Beans
MainForm.java
DwarfForm.java
MountainForm.java

The Controller portion of the struts framework automatically copies data between the Model Form Beans and the View JSP pages. The controller logic for each page is implemented in subclasses of the Action class:

Action Classes
EnterMainAction.java
AddDwarfAction.java
EditDwarfAction.java
SaveDwarfAction.java
AddMountainAction.java
EditMountainAction.java
SaveMountainAction.java

The page flow and the relationships between the models, views, and controllers are configured in the struts-config.xml file.

Underneath the model the data is stored in the Postgresql SQL database. The following database files were used:

SQL Files
Dwarf_Schema.sql
Dwarf_Load.sql
Drop_Database.sql

Java Bean data objects were defined to encapsulate data returned from the database:

Data Objects
Dwarf.java
Mountain.java

Rows from the Database object are initially returned as a DbRowSet, but are copied to lists of data objects because the Struts APIs and tag libraries operate on Java Beans, not list-of-hash-style RowSets [note the difference with ASP.NET, whose controls accept ADO.NET database DataSets directly]. Database queries are performed inside Mgr objects:

Mgr Objects
DwarfMgr.java
MountainMgr.java

Struts also supports separate message catalogs for localization. Dwarf Manager does not use this facility, except the Form validation will return error messages from the ApplicationResources.properties file.

While Java Dwarf Manager does require more code than the C# equivalent, some of this code can be produced using a Code Generator.

The simple back-end jdbc database classes can also be replaced with EJBs.

The source for the Java Dwarf Manager web site is available in this tar file. All code was developed using Java 1.3.1 on Mac OS X.